/*
** epur_str.c for epur_str in /exam/rendu/ex_5
** 
** Made by thomas nadalie
** Login   <nadali_t@epitech.net>
** 
** Started on  Sat Oct 27 10:25:19 2012 thomas nadalie
** Last update Thu Nov  8 12:25:04 2012 thomas nadalie
*/

#include	<stdlib.h>
#include	"my.h"

char            *epur_str(char *str)
{
  int           i;
  int           j;
  char		*buf;

  i = 0;
  j = 0;
  if ((buf = malloc(sizeof(buf) * my_strlen(str))) == NULL)
    return (NULL);
  while (str[i] == ' ' || str[i] == '\t')
    i++;
  while (str[i])
    {
      if (str[i] == ' ' || str[i] == '\t')
	{
	  buf[j++] = ' ';
	  while (str[i] == ' ' || str[i] == '\t')
	    i++;
	}
    buf[j++] = str[i++];
    }
  buf[j] = '\0';
  if (buf[j - 1] == ' ')
    buf[j - 1] = '\0';
  return (buf);
}
